package com.itfenghuang.day13;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

// TCP协议 客户端
public class A08_TCPClient {
    public static void main(String[] args) throws IOException {
        /**
         *
         *  客户端发送消息给服务端,服务端接收到消息打印在控制台上
         */
        Socket socket = new Socket("127.0.0.1",10086);
        // 发送数据 获取输出流
        OutputStream os = socket.getOutputStream();
        os.write("哈哈哈".getBytes());
        //获取服务端返回的数据
        InputStream is = socket.getInputStream();
        byte[] bys=new byte[1024];
        int i = is.read(bys);
        System.out.println(new String(bys,0,i));
        socket.close();



    }
}
